package com.adopapa.importexcel;

import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class SheetContent {

	private String[] fieldNames = null;

	private String[] titles = null;

	private Map<String, Object[]> fieldValuesMap = null;

	private List<String> uniqueFields = null;

	private int fieldCount;

	private int contentCount;

	public SheetContent(int fieldCount, int contentCount) {

		fieldNames = new String[fieldCount];
		titles = new String[fieldCount];
		fieldValuesMap = new ConcurrentHashMap<>();
		uniqueFields = new LinkedList<>();

		this.fieldCount = fieldCount;
		this.contentCount = contentCount;

	}

	public void addFieldName(int index, String fieldName) {
		fieldNames[index] = fieldName;
	}

	public void addTitle(int index, String title) {
		titles[index] = title;
	}

	public void addUnique(String fieldName) {
		uniqueFields.add(fieldName);
	}

	public void addFieldValue(int fieldCount, int contentCount, Object fieldValue) {
		Object[] fieldValues = fieldValuesMap.get(fieldNames[fieldCount]);
		if (fieldValues == null) {
			fieldValues = new Object[this.contentCount];
		}
		fieldValues[contentCount] = fieldValue;
		fieldValuesMap.put(fieldNames[fieldCount], fieldValues);
	}
	
	public Object[] getFieldValues(String fieldName) {
		return fieldValuesMap.get(fieldName);
	}

	public String[] getFieldNames() {
		return fieldNames;
	}

	public void setFieldNames(String[] fieldNames) {
		this.fieldNames = fieldNames;
	}

	public String[] getTitles() {
		return titles;
	}

	public void setTitles(String[] titles) {
		this.titles = titles;
	}

	public Object getFieldValue(int fieldCount, int contentCount) {
		Object[] fieldValues = fieldValuesMap.get(fieldNames[fieldCount]);
		if (fieldValues == null) {
			return null;
		}
		return fieldValues[contentCount];
	}


	public int getFieldCount() {
		return fieldCount;
	}

	public void setFieldCount(int fieldCount) {
		this.fieldCount = fieldCount;
	}

	public int getContentCount() {
		return contentCount;
	}

	public void setContentCount(int contentCount) {
		this.contentCount = contentCount;
	}

	public List<String> getUniqueFields() {
		return uniqueFields;
	}

}
